﻿(function ($) {
    bensie = jQuery;
    var api = {
        showShade: function () {
            if ($('#__bsy_ui_shade').size() > 0) { $('#__bsy_ui_shade').remove(); }
            $('<div id="__bsy_ui_shade"></div>').appendTo($(document.body));
        },
        hideShade: function () { $('#__bsy_ui_shade').remove(); },

        messageBox: function (options) {
            var defaults = { isArea: '', id: '', buttons: 'Ok', title: '', message: '提示', btnOkText: '确定', okClickClose: true, onOkClick: function (data) { }, btnCancelText: '取消', onCancelClick: function () { } };
            var ps = $.extend(defaults, options);
            //if (document.getElementById('__bsy_dialog') != undefined) { api.__close(); }
            if (document.getElementById('__bsy_dialog') != undefined) { $('#__bsy_dialog').remove(); }
            //var dialogContainer = $('<div id="__bsy_dialog" style="display:none"></div>').appendTo($(document.body));
            //var dialogContainer = $('<div id="__bsy_dialog" style="position:absolute;top:-1000rem;left:-1000rem"></div>').appendTo($(document.body));
            var dialogContainer = $('<div id="__bsy_dialog" ></div>').appendTo($(document.body)).hide();
            var dialogCaption = $('<h2>' + ps.title + '</h2>').appendTo(dialogContainer);
            var dialogContent = $('<div id="__bsy_dialog_content">' + ps.message + '</div>').insertAfter(dialogCaption);
            var dialogButtons = $('<div id="__bsy_dialog_buttons"></div>').insertAfter(dialogContent);
            var dialogButtonCancel = $('<input id="__bsy_dialog_button_cancel" class="__bsy_button_normal" type="button" value="' + ps.btnCancelText + '" />');
            var dialogButtonOk = $('<input id="__bsy_dialog_button_ok" class="__bsy_button_normal" type="button" value="' + ps.btnOkText + '" />');
            var idPreObject;
            if (ps.id != '') {
                var idPreObject = $('#' + ps.id).parent();
                if (idPreObject.size() == 0) { idPreObject = $(document.body); }
                api.globalVar.__id = ps.id;
                api.globalVar.__idPreObject = idPreObject;
                dialogContent.html('');
                dialogContent.wrapInner($('#' + ps.id).show());
            }

            if (ps.buttons == 'OkCancel') {
                dialogButtonCancel.appendTo(dialogButtons).css({ width: '50%', 'border-right': '1px solid #ddd', 'border-bottom-right-radius': 0 });
                dialogButtonOk.insertAfter(dialogButtonCancel).css({ width: '50%', 'border-bottom-left-radius': 0 });
            }
            else {
                dialogButtonOk.appendTo(dialogButtons);
            }

            if (ps.title == '') { dialogCaption.remove(); }

            var bensieSize = api.__getPosition();
            if (ps.isArea == '') {
                dialogContainer.css({ left: bensieSize.left + 'px', top: bensieSize.top + 'px' });
            }
            else {
                dialogContainer.css({ left: bensieSize.left + 'px', top: '100px' });
            }

            setTimeout(function () {
                api.showShade();
                dialogContainer.show();
            }, api.globalVar.__timeOut);

            function btnClick() {
                api.hideShade();
                if (ps.id != '') { $('#' + ps.id).appendTo(idPreObject).hide(); }
                dialogContainer.remove();
            }

            dialogButtonCancel.click(function () {
                api.__close();
                ps.onCancelClick();
            });

            dialogButtonOk.click(function () {
                if (ps.okClickClose) { api.__close(); }
                ps.onOkClick();
            });

        }, //end of messageBox
        __getPosition: function () {
            var dialogContainer = $('#__bsy_dialog');
            var pageViewWidth = $(window).width();
            var pageViewHeight = $(window).height();
            var scrollTop = $(document).scrollTop();
            if (api.isIphone()) {
                pageViewHeight = window.screen.height - 64; //64是iphone微信顶部的ActionBar
                var pageContent = $('#page-content');
                if (pageContent.length > 0) { scrollTop = pageContent.scrollTop(); }
            }
            var scrollLeft = $(document).scrollLeft();
            var width = dialogContainer.outerWidth();
            var height = dialogContainer.outerHeight(true);
            var top = (pageViewHeight - height) / 2;
            var left = (pageViewWidth - width) / 2 + scrollLeft;
            if (!api.isIphone()) { top += scrollTop; }

            return { left: left, top: top };
        },
        __close: function () {
            api.hideShade();
            var id = api.globalVar.__id;
            if (id != '') { $('#' + id).appendTo(api.globalVar.__idPreObject).hide(); }
            api.globalVar.__idPreObject = null;
            $('#__bsy_dialog').remove();
        },
        alert: function (options) {
            var defaults = { title: '', message: '', btnOkText: '确定', onOkClick: function () { } };
            var ps = $.extend(defaults, options);
            api.messageBox({ message: ps.message, buttons: ps.buttons, title: ps.title, btnOkText: ps.btnOkText, onOkClick: ps.onOkClick });
        },
        confirm: function (options) {
            var defaults = { title: '', message: '', btnOkText: '确定', onOkClick: function () { }, btnCancelText: '取消', onCancelClick: function () { } };
            var ps = $.extend(defaults, options);
            api.messageBox({ message: ps.message, buttons: 'OkCancel', title: ps.title, btnOkText: ps.btnOkText, onOkClick: ps.onOkClick, btnCancelText: ps.btnCancelText, onCancelClick: ps.onCancelClick });
        },
        popup: function (options) {
            var defaults = { id: '', title: '', buttons: 'OkCancel', btnOkText: '确定', onOkClick: function () { }, btnCancelText: '取消', onCancelClick: function () { } };
            var ps = $.extend(defaults, options);
            api.messageBox({ id: ps.id, buttons: ps.buttons, title: ps.title, btnOkText: ps.btnOkText, okClickClose: false, onOkClick: ps.onOkClick, btnCancelText: ps.btnCancelText, onCancelClick: ps.onCancelClick });
        },
        loadPage: function (options) {
            var defaults = { url: '', buttons: 'Ok', btnCancelText: '取消', btnOkText: '确定', okClickClose: true, onCancelClick: function (data) { }, onOkClick: function (data) { } };
            var ps = $.extend(defaults, options);
            var dialogContainer = $('<div id="__bsy_dialog" style="border-radius:0;border:0;top:0;left:0;padding:0;margin:0"></div>').appendTo($(document.body));
            var dialogContent = $('<div id="__bsy_dialog_content" style="margin:0;padding:0;width:100%;overflow-x:hidden"></div>').appendTo(dialogContainer);
            var dialogFrame = $('<iframe frameborder="0" style="margin:0;padding:0;width:100%;overflow-x:hidden" src="' + ps.url + '"></iframe>').appendTo(dialogContent);

            function setSize() {
                var wnHeight = $(window).height();
                var frameHeight = wnHeight;
                dialogContainer.css({ width: $(window).width() + 'px', height: wnHeight + 'px' });
                dialogContent.css({ height: frameHeight + 'px' });
                dialogFrame.css({ height: frameHeight + 'px' });
            }

            setSize();

            $(window).resize(function () {
                setSize();
            });
        },
        __closeLoadPage: function () {
            $(parent.document).find('#__bsy_dialog').remove();
        },
        areaSelector: function (options) {
            var defaults = {
                title: '选择区域',
                selectModel: 4, // 省=1； 省市=2； 省市区=3； 省市区镇=4； 省市区镇地址=5
                init: { editMode: false, provinceId: -1, cityId: -1, districtId: -1, townId: -1, address: '' },
                btnOkText: '确定',
                onOkClick: function (data) { },
                btnCancelText: '取消',
                onCancelClick: function () { },
                okClickClose: true
            };
            var ps = $.extend(defaults, options);
            if ($('#__bsy_area_container').size() > 0) { $('#__bsy_area_container').remove(); }
            var elemContainer = $('<div id="__bsy_area_container"></div>').appendTo($(document.body));
            var elemProvince = $('<select id="__bsy_area_province"><option value="-1">选择省</option></select>').appendTo(elemContainer);
            var elemCity = $('<select id="__bsy_area_city"><option value="-1">选择市</option></select>').insertAfter(elemProvince);
            var elemDistrict = $('<select id="__bsy_area_district"><option value="-1">选择县(区)</option></select>').insertAfter(elemCity);
            var elemTown = $('<select id="__bsy_area_town"><option value="-1">选择镇</option></select>').insertAfter(elemDistrict);
            var elemInput = $('');
            if (ps.selectModel == 5) {
                elemInput = $('<input id="__bsy_area_input" style="display: block;width: 100%;height: 2.2rem;font-size: 1rem;padding-left: 2%;margin: 1.5rem 0;" value="' + ps.init.address + '" />').appendTo(elemContainer);
            }

            var provinceJson = __provinceJsonForBensie;
            for (var key in provinceJson) {
                $('<option value="' + provinceJson[key].Id + '">' + provinceJson[key].Name + '</option>').appendTo(elemProvince);
            }

            function setCity(pid, val) {
                var cityJson = __cityJsonJsonForBensie;
                $('option:gt(0)', elemCity).remove();
                for (var key in cityJson) {
                    if (cityJson[key].PId != pid) { continue; }
                    $('<option value="' + cityJson[key].Id + '">' + cityJson[key].Name + '</option>').appendTo(elemCity);
                }
                if (val != -1) { elemCity.val(val); }
            }
            function setDistrict(pid, val) {
                var districtJson = __districtJsonForBensie;
                $('option:gt(0)', elemDistrict).remove();
                for (var key in districtJson) {
                    if (districtJson[key].PId != pid) { continue; }
                    $('<option value="' + districtJson[key].Id + '">' + districtJson[key].Name + '</option>').appendTo(elemDistrict);
                }
                if (val != -1) { elemDistrict.val(val); }
            }
            function setTown(pid, val) {
                var townJson = __townJsonForBensie;
                $('option:gt(0)', elemTown).remove();
                var selectedValue = $('#' + elemDistrict.get(0).id).val();
                for (var key in townJson) {
                    if (townJson[key].PId != pid) { continue; }
                    $('<option value="' + townJson[key].Id + '">' + townJson[key].Name + '</option>').appendTo(elemTown);
                }
                if (val != -1) { elemTown.val(val); }
            }

            //编辑模式，初始化
            if (ps.init.editMode) {
                elemProvince.val(ps.init.provinceId);
                setCity(ps.init.provinceId, ps.init.cityId);
                setDistrict(ps.init.cityId, ps.init.districtId);
                setTown(ps.init.districtId, ps.init.townId);
            }

            //事件
            elemProvince.change(function () {
                var selectedValue = $('#' + elemProvince.get(0).id).val();
                setCity(selectedValue, -1);
                elemDistrict.val(-1);
                setDistrict(-1, -1);
                elemTown.val(-1);
                setTown(-1, -1);
            });
            elemCity.change(function () {
                var selectedValue = $('#' + elemCity.get(0).id).val();
                setDistrict(selectedValue, -1);
                elemTown.val(-1);
                setTown(-1, -1);
            });
            elemDistrict.change(function () {
                var selectedValue = $('#' + elemDistrict.get(0).id).val();
                setTown(selectedValue, -1);
            });

            api.messageBox({
                isArea: '1',
                id: elemContainer.get(0).id,
                title: ps.title,
                buttons: 'OkCancel',
                btnOkText: ps.btnOkText,
                onOkClick: function (d) {
                    var address = '';
                    if (ps.selectModel == 5) {
                        address = $('#' + elemInput.get(0).id).val();
                    }
                    var data = {
                        provinceId: $('#' + elemProvince.get(0).id).val(),
                        provinceName: $('#' + elemProvince.get(0).id + ' option:selected').text(),
                        cityId: $('#' + elemCity.get(0).id).val(),
                        cityName: $('#' + elemCity.get(0).id + ' option:selected').text(),
                        districtId: $('#' + elemDistrict.get(0).id).val(),
                        districtName: $('#' + elemDistrict.get(0).id + ' option:selected').text(),
                        townId: $('#' + elemTown.get(0).id).val(),
                        townName: $('#' + elemTown.get(0).id + ' option:selected').text(),
                        address: address
                    };
                    ps.onOkClick(data);
                },
                btnCancelText: ps.btnCancelText,
                onCancelClick: ps.onCancelClick,
                okClickClose: ps.okClickClose
            });

        }, //end of areaSelector
        loadMore: function (options) {
            var defaults = { id: 'bensie-data-list', url: '', params: {}, actionType: '', pageIndex: 0, pageSize: 20, noRecordTip: '暂无相关记录！', success: function (result) { } };
            var ps = $.extend(defaults, options);
            var url = ps.url;
            var urlStarChar = '?';
            if (url.indexOf('?') != -1) { urlStarChar = '&'; }
            var urlParams = urlStarChar;
            $.each(ps.params, function (key, value) { urlParams += key + '=' + value + '&'; });
            var pageIndex = 0;
            var loadMoreObject = $('#bensie-load-more');
            var isAppend = true;
            if (ps.pageIndex > 0) { pageIndex = ps.pageIndex; api.globalVar.__pageIndex = pageIndex; isAppend = false; } else { pageIndex = api.globalVar.__pageIndex; }
            $.ajax({
                data: ps.params, cache: false, dataType: 'json',
                url: ps.url + urlStarChar + '&requestType=ajax&actionType=' + ps.actionType + '&' + '&pageIndex=' + pageIndex + '&pageSize=' + ps.pageSize,
                beforeSend: function () {
                    loadMoreObject.text('加载中……');
                },
                success: function (data) {
                    var result = data.html;
                    if ($.trim(result) == '') {
                        if (pageIndex == 1) {
                            $('#' + ps.id).html(ps.noRecordTip);
                        }
                        loadMoreObject.hide();
                    }
                    else {
                        var recordCount = data.recordCount;
                        if (isAppend) { $('#' + ps.id).append(result); } else { $('#' + ps.id).html(result); }
                        if (api.globalVar.__pageIndex * ps.pageSize > recordCount) {
                            loadMoreObject.hide();
                        } else {
                            loadMoreObject.show();
                        }
                        api.globalVar.__pageIndex++;
                        loadMoreObject.text('加载更多');
                    }
                    if (ps.pageSize * pageIndex >= data.recordCount) { loadMoreObject.hide(); }
                    var dataResult = {};
                    for (var o in data) { if (o != 'html') { dataResult[o] = data[o]; } }
                    ps.success(dataResult);
                },
                error: function () {
                    alert('暂无法请求数据，请稍候重试！');
                }
            });
        }, // end of loadMore
        showLoading: function (options) {
            var defaults = { message: '处理中，请稍后……', timeOut: 0, title: '' };
            var ps = $.extend(defaults, options);
            var url = window.location.href;
            if (document.getElementById('__bsy_dialog') != undefined) { return; }
            var dialogContainer = $('<div id="__bsy_dialog" class="__bsy_loading_css"></div>').appendTo($(document.body));
            var title = '';
            if (ps.title != '') {
                title = '<span style="font-weight: bold;font-size: 110%">' + ps.title + '</span><br><br>';
            }
            var dialogContent = $('<div id="__bsy_dialog_content" style="line-height:2rem">' + title + '<img src="' + api.getBensieUrl() + '/loading.gif" style="vertical-align:middle" /><span style="padding-left:0.5rem">' + ps.message + '</span></div>').appendTo(dialogContainer);

            var bensieSize = api.__getPosition();
            dialogContainer.css({ left: bensieSize.left + 'px', top: bensieSize.top + 'px' });

            api.showShade();
        }, //end of loading
        closeLoading: function (options) {
            var defaults = { timeOut: 500 };
            var ps = $.extend(defaults, options);
            api.globalVar.__timeOut = ps.timeOut;
            setTimeout(function () {
                api.hideShade();
                $('.__bsy_loading_css').remove();
            }, ps.timeOut);
        },
        getBensieUrl: function () {
            var scripts = $("script");
            for (var i = 0; i < scripts.size(); i++) { if (scripts[i].src.indexOf('/bensie/') != -1) { return scripts[i].src.split('/bensie/')[0] + '/bensie'; } }
            return '';
        },
        request: function (name) {
            var url = window.location.href;
            var paramString = url.split('?');
            if (paramString.length == 1) { return ''; }
            var params = paramString[1].split('&');
            for (var i = 0; i < params.length; i++) {
                var kvs = params[i].split('=');
                if (kvs.length == 1) { continue; }
                if (kvs[0].toLowerCase() == name.toLowerCase()) { return kvs[1]; }
            }
            return '';
        }, // end of request
        scanWxQRCode: function (options) {
            var defaults = { cancel: function () { }, success: function (data) { }, fail: function () { }, error: function (ex) { } };
            var ps = $.extend(defaults, options);
            try {
                parent.parent.ScanQRCode();
                var k = 0;
                var checkResult = setInterval(function () {
                    var scanResult = parent.parent.document.getElementById("weixinScanResult").value;
                    if (k = 0) { alert(k); k = 1; }
                    if (scanResult == null || scanResult == '') {
                        return;
                    }
                    switch (scanResult) {
                        case 'fail': ps.fail(); break;
                        case 'cancel': ps.cancel(); break;
                        case 'success': ps.success(scanResult); break;
                    }
                    clearInterval(checkResult);
                }, 1000);
                //setTimeout("__checkScanQRCodeResultForInner()", 1000);
            }
            catch (ex) {
                ps.error(ex);
            }
        },
        isIphone: function () {
            return navigator.userAgent.toString().toLocaleLowerCase().indexOf('iphone') != -1;
        },
        isMobile: function (mobile) {
            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
            return myreg.test(mobile);
        },
        isPhone: function (phone) {
            var myreg = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
            return myreg.test(phone);
        },
        isEmail: function (email) {
            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            return myreg.test(email);
        },
        /* 验证身份证号码，返回string类型 */
        isIdCard: function (idcard) {
            //返回值（格式：1、身份证验证错误(Errors[])   2、通过验证(areacode + "|" + birthday + "|" + sex)）
            var areacode = ""; //地区
            var birthday = ""; //出生日期(年-月-日)
            var sex = ""; //性别
            var Errors = new Array(
	                    "身份证号码位数不对！",
	                    "身份证号码出生日期超出范围或含有非法字！",
	                    "身份证号码校验错误！",
	                    "身份证地区非法！"
	                    );
            var area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海",
                32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西",
                46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆",
                71: "台湾", 81: "香港", 82: "澳门", 91: "国外"
            };
            var Y, JYM;
            var S, M;
            var idcard_array = new Array();
            idcard_array = idcard.split("");
            //地区检验
            if (area[parseInt(idcard.substr(0, 2))] == null) {
                return (Errors[3]);
            }
            else {
                areacode = area[parseInt(idcard.substr(0, 2))];
            }
            //身份号码位数及格式检验
            switch (idcard.length) {
                case 15:
                    //出生日期的合法性检查
                    if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0 || ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0)) {
                        //测试出生日期的合法性
                        ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;
                    }
                    else {
                        //测试出生日期的合法性
                        ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;
                    }
                    if (ereg.test(idcard)) {
                        birthday = (parseInt(idcard.substr(6, 2), 10) + 1900) + "-" + idcard.substr(8, 2) + "-" + idcard.substr(10, 2); //年-月-日
                    }
                    else {
                        return (Errors[1]);
                    }
                    //性别
                    if (parseInt(idcard.substr(14, 1)) % 2 == 1)
                        sex = "男";
                    else
                        sex = "女";
                    break;
                case 18:
                    //18位身份号码检测
                    //出生日期的合法性检查 
                    //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
                    //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
                    if (parseInt(idcard.substr(6, 4)) % 4 == 0 || parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard.substr(6, 4)) % 4 == 0) {
                        //闰年出生日期的合法性正则表达式
                        ereg = /^[1-9][0-9]{5}((19[0-9]{2})|20[0-9]{2})((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;
                        //闰年出生日期的合法性正则表达式
                    }
                    else {
                        //平年出生日期的合法性正则表达式
                        ereg = /^[1-9][0-9]{5}((19[0-9]{2})|20[0-9]{2})((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;
                    }
                    if (ereg.test(idcard)) {
                        birthday = idcard.substr(6, 4) + "-" + idcard.substr(10, 2) + "-" + idcard.substr(12, 2); //年-月-日
                    }
                    else {
                        return (Errors[1]);
                    }
                    //计算校验位
                    S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
			        + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
			        + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
			        + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
			        + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
			        + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
			        + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
			        + parseInt(idcard_array[7]) * 1
			        + parseInt(idcard_array[8]) * 6
			        + parseInt(idcard_array[9]) * 3;
                    Y = S % 11;
                    M = "F";
                    JYM = "10X98765432";
                    M = JYM.substr(Y, 1); //判断校验位
                    if (M != idcard_array[17].toUpperCase()) {
                        return (Errors[2]);
                    }
                    //性别
                    if (parseInt(idcard.substr(16, 1)) % 2 == 1)
                        sex = "0"; //男
                    else
                        sex = "1"; //女
                    break;
                default:
                    return (Errors[0]);
                    break;
            }
            return (sex);
        },
        doAjax: function (options) {
            var defaults = { url: '', data: {}, success: function (res) { }, timeOut: function () { } };
            var ps = $.extend(defaults, options);

            var url = ps.url;
            var urlStarChar = '?';
            if (url.indexOf('?') != -1) { urlStarChar = '&'; }
            var urlParams = urlStarChar;
            $.each(ps.data, function (key, value) { urlParams += key + '=' + value + '&'; });

            var requestUrl = ps.url + urlParams;
            console.log(requestUrl);

            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = stateChange;
            xmlhttp.open("GET", requestUrl + urlParams, true);
            xmlhttp.send(null);

            function stateChange() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var json = $.parseJSON(xmlhttp.responseText);
                    ps.success(json);
                }
            }
        }, // end of ajax
        globalVar: { __id: '', __idPreObject: null, __pageIndex: 2, __timeOut: 500 }
    };
    bensie.alert = api.alert;
    bensie.confirm = api.confirm;
    bensie.popup = api.popup;
    bensie.close = api.__close;
    bensie.areaSelector = api.areaSelector;
    bensie.loadMore = api.loadMore;
    bensie.loading = { show: api.showLoading, close: api.closeLoading };
    bensie.request = api.request;
    bensie.scanWxQRCode = api.scanWxQRCode;
    bensie.isIphone = api.isIphone;
    bensie.isMobile = api.isMobile;
    bensie.isPhone = api.isPhone;
    bensie.isEmail = api.isEmail;
    bensie.isIdCard = api.isIdCard;
    bensie.doAjax = api.doAjax;
    bensie.loadPage = { show: api.loadPage, close: api.__closeLoadPage };
})($);

